pub mod advanced_agents;
pub mod agent_types;
pub mod agents;
pub mod builtin_tools;
pub mod completion;
pub mod config;
pub mod embedding;
pub mod errors;
pub mod image;
pub mod knowledge_base;
pub mod monitoring;
pub mod performance;
pub mod security;
pub mod tools;

pub use advanced_agents::{
    AdvancedAgentManager, OrchestrationMode, RoutingRule, StepResult, WorkflowConfig,
    WorkflowResult, WorkflowStep, WorkflowTool, WorkflowToolArgs,
};
pub use agent_types::{AgentCategory, EnhancedAgentConfig, KnowledgeBaseConfig, VectorDbConfig};
pub use agents::{AgentConfig, AgentManager, ChatMessage};
pub use builtin_tools::{BuiltinTool, CalculatorArgs};
pub use completion::{chat, prompt, stream_chat};
pub use config::{AppConfig, DatabaseConfig, EmbeddingConfig, ImageConfig, ProviderConfig};
pub use embedding::{
    create_embedding_agent, rag_query, EmbeddingDocument, EmbeddingManager, EmbeddingSearchResult,
};
pub use errors::{AppError, AppResult, ContextualError, ErrorCategory, ErrorContext};
pub use image::{
    analyze_with_agent, create_image_agent, generate_with_agent, GeneratedImage,
    ImageAnalysisRequest, ImageAnalysisResponse, ImageGenerationRequest, ImageManager,
};
pub use knowledge_base::{KbDocument, KnowledgeBase};
pub use monitoring::{Alert, HealthStatus, LogEntry, LogLevel, MonitoringManager};
pub use performance::{PerformanceManager, PerformanceMetrics, PerformanceSummary};
pub use security::{ApiKeyInfo, SecurityManager, SecurityMiddleware, SessionInfo};
pub use tools::{
    MCPProtocol, MCPServiceConfig, MCPServiceError, MCPServiceManager, MCPToolCallRequest,
    MCPToolCallResponse, MCPToolDefinition, ToolDefinition, ToolManager,
};

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::TempDir;

    #[test]
    fn test_agent_creation() -> anyhow::Result<()> {
        let temp_dir = TempDir::new()?;
        let agents_file = temp_dir.path().join("agents.json");
        let _tools_file = temp_dir.path().join("tools.json");

        let agent_manager = AgentManager::new(&agents_file)?;
        // Create a chat agent using the sync method
        let agent_id = agent_manager.create_agent_sync(
            "Test Agent",
            "openai",
            "gpt-4",
            "You are a test agent.",
            None,
            Some(&["calculator".to_string()]),
            AgentCategory::Chat,
            None,
        )?;

        assert_eq!(agent_id, 1);

        // Test getting the agent using the sync method
        let agent = agent_manager.get_agent_sync(agent_id)?;
        assert!(agent.is_some());

        let agent = agent.unwrap();
        assert_eq!(agent.base_config.name, "Test Agent");
        assert_eq!(agent.category, AgentCategory::Chat);

        Ok(())
    }
}
